<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>crypto-js_aes加密测试</title>
  <script text="text/javascript" src="./lib/crypto-js.js"></script>
</head>
<body>
</body>
<script>
  // console.log(CryptoJS)
  // console.log(CryptoJS.AES.encrypt) // config  mode  padding  第三个参数 iv
  // console.log( CryptoJS.mode); // 工作模式

  // 加密数据
  var encStr = CryptoJS.AES.encrypt("This is the 测试数据", "123456");
  console.log("加密的数据", encStr);

  var bytes = CryptoJS.AES.decrypt(encStr, '123456');
  var originalText = bytes.toString(CryptoJS.enc.Utf8);
  console.log('解密的数据', originalText);

  // IV初始向量IV（Initialization Vector）
  // IV是做什么用的呢？它的作用和MD5的“加盐”有些类似，目的是防止同样的明文块始终加密成同样的密文块。

var key = CryptoJS.enc.Hex.parse("000102030405060708090a0b0c0d0e0f");
var iv = CryptoJS.enc.Hex.parse("101112131415161718191a1b1c1d1e1f");
var encrypted = CryptoJS.AES.encrypt("This is the 测试数据", key, { iv: iv });
console.log('加了盐的数据', encrypted.toString());
console.log('解密加了盐的数据', CryptoJS.AES.decrypt("AXuGfzVlvOzMMw54pq6u5j77ghWsxT/y8QPxfsZKjt4=", "8102992657E5715D71CB7270E537A41A").toString(CryptoJS.enc.Utf8));
//CryptoJS supports AES-128, AES-192, and AES-256. It will pick the variant by the size of the key you pass in. If you use a passphrase, then it will generate a 256-bit key.
// 来源: https://cryptojs.gitbook.io/docs/#ciphers
</script>
</html>